<!DOCTYPE html>
<html>
	<head>
		<title>custom</title>
		<style>
			div{
				width:100px;
				height:100px;
				border:1px solid black;
			}
		</style>
	</head>
	<body>
		<input type="button" value="自定义属性" id="custom"/>
		<div>
			qq
		</div>
	</body>
	<script>
		window.onload = function (){
			var objBtn = document.getElementsByTagName("input");
			addAttribute();
			objBtn[0].onclick = customBtn;
		}
		
		function addAttribute(){
			var objArr = document.getElementsByTagName("div");
			objArr[0].setAttribute("index","2");
		}
		
		function customBtn (){
			
			var objArr = document.getElementsByTagName("div")[0];
			alert(objArr.index);
		}
	</script>
</html>